const permissionList = [];

export function isloadPermission(){
    if(permissionList.length==0){
        return false;
    }
    return true;
}

export function setPermission(data){
    for(var i = 0; i <data.length; i++){
        permissionList.push(data[i]);
        
    }
}

export function hasPermission(permission){

    for(let i = 0; i <permissionList.length; i++){
        if(permission==permissionList[i]){
            return true;
        }
    }
    return false;
}

export function judgePermission(prePerm){
    let savePermission = false;
    let editPermission = false;
    let deletePermission = false;
    
    for(let i = 0; i <permissionList.length; i++){
        
        if((prePerm+":save")==permissionList[i]){
            savePermission = true;
        }
        if((prePerm+":update")==permissionList[i]){
            editPermission = true;
        }

        if((prePerm+":delete")==permissionList[i]){
            deletePermission = true;
        }
        if(savePermission&&editPermission&&deletePermission) {
            break;
        }
    }
    return {
        save:savePermission,
        edit:editPermission,
        delete:deletePermission,
    };
}



// export async function isAllowed(permission){
//     if(permissionList.length==0){
//         //权限数据未初始化
//         var response = getPermissions().then(function(data){
//             return "asdfsdafsdafsadfxxxxxx";
//         });
//         return response;
//     }else{
//         for(let i = 0; i <permissionList.length; i++){
//             if(permission==permissionList[i]){
//                 return true;
//             }
//         }
//         return false;
//     }
// }

// export const hasPermission = (permission) => isAllowed(permission);